/*
 * @Descripttion: 
 * @version: 
 * @Author: Terry
 * @Date: 2020-06-04 17:18:56
 * @LastEditors: Terry
 * @LastEditTime: 2024-08-21 23:56:33
 */ 
// vue.config.js
const path = require('path')
function resolve(dir) {
    return path.join(__dirname, dir)
}
const CompressionPlugin = require('compression-webpack-plugin');//引入gzip压缩插件
const FileManagerPlugin = require('filemanager-webpack-plugin')
const name = '智慧建筑一体化管理平台' // 网页标题 可配置 改成 process.env.xxx
const Version = new Date().getTime() //打包时间戳 防止缓存
module.exports = {
    runtimeCompiler: true,
    publicPath:'/',
    outputDir: process.env.VUE_APP_FILE_Name,
    parallel: false,
    assetsDir: 'static',
    productionSourceMap: false,
    devServer: {
        hot:true,
      client:{
        overlay:false,
      },
        port: 8080,
        proxy: {
            '/api': {
                target:  process.env.VUE_APP_BASE_API,  // target host
                ws: true,  // proxy websockets 
                changeOrigin: true,  // needed for virtual hosted sites
            },
        },
    },
    css: {
        loaderOptions: {
            sass: {
              sassOptions: { outputStyle: "expanded" }
            },
            less: {
              lessOptions: {
                  javascriptEnabled: true,
              },
            },
        },
        extract: {
            filename: `css/[name].${Version}.css`,
            chunkFilename: `css/[name].${Version}.css`,
        }
    },
    configureWebpack: {
        name: name,
        output: {
            filename: `js/[name].${Version}.js`,
            chunkFilename: `js/[name].${Version}.js`,
        },
        resolve: {
          alias: {
            '@': resolve('src'),
            '@assets': resolve('src/assets'),
          }
        },
        plugins: [
          new CompressionPlugin({
            // cache: false,                   // 不启用文件缓存
            test: /\.(js|css|html)?$/i,     // 压缩文件格式
            filename: '[path].gz[query]',   // 压缩后的文件名
            algorithm: 'gzip',              // 使用gzip压缩
            minRatio: 0.8                   // 压缩率小于1才会压缩
          })
        ],
        // 设置 externals
        externals:{
            'AMap': 'AMap', // 高德地图配置
        }
    },
};